//
//  UIView+LHAddTapgesture.m
//  GodPlay
//
//  Created by Kris Hsu on 2018/3/23.
//  Copyright © 2018年 Kris Hsu. All rights reserved.
//

#import "UIView+LHAddTapgesture.h"

#import <objc/runtime.h>
#import <objc/message.h> 


const void *UIView_key_tapBlock;


@implementation UIView (LHAddTapgesture)

-(void) addTapGestureWithBlock:(tapBlock) block{
    self.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionTap:)];
    [self addGestureRecognizer:tap];
    
    objc_setAssociatedObject(self, UIView_key_tapBlock, block, OBJC_ASSOCIATION_COPY);
}

-(void)actionTap:(UITapGestureRecognizer *)sender{
    tapBlock block = objc_getAssociatedObject(self, UIView_key_tapBlock);
    
    if (block) block(sender);
}



@end
